<?php

function getthemecust() {
    $SERVER_NAME = $_SERVER["SERVER_NAME"];
    list($config_instance) = split("[/.]", $SERVER_NAME, 2);
    
    //echo $SERVER_NAME . " | " . $config_instance;
    
    $base_config_dir = "/var/www/endeepen/instances/";
    
    $instance_path = $base_config_dir . $config_instance . "/" .  $config_instance. ".xml";
    
    $theme_customization_path = $base_config_dir . $config_instance . "/theme/topic.xml";
    
    $check_for_config = file_exists($theme_customization_path);

    $theme_customizations = "<!-- no customization found -->";

    if ($check_for_config){
        
        $xml_config_data = file_get_contents($theme_customization_path);
                
        $customization_xml = new SimpleXMLElement($xml_config_data);
        
        $custom_styles = $customization_xml->styles;
        
        $type_treatments = $custom_styles->type_treatments;
        
        $working_customizations = "<style type='text/css'> \n <!-- \n";
        
        foreach ($type_treatments->children() as $typestyle)
        {
           $thestyle = $typestyle->getName() . "{" . "\n";
           
           foreach ($typestyle->children() as $stylelement){
                $thestyle .= $stylelement->getName() . ":";
                $thestyle .= $stylelement . "; \n";
           }
           $thestyle .= "} \n";
           $working_customizations .= $thestyle;
        }

        
        $working_customizations .= "--></style>";
        
        $theme_customizations = $working_customizations;


    }
    
    return $theme_customizations;
  
}


 echo "themecust = " . getthemecust();


?>